﻿using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;

namespace MetroGTD.Model
{
    public interface IThingsDataContext
    {
        IEnumerable<Thing> GetThings();
        IEnumerable<Thing> GetThings(Tag tag);
        void SaveThing(Thing thing);
    }

    public class ThingsDataContext : DbContext, IThingsDataContext
    {
        public DbSet<Thing> Things { get; set; }
        public DbSet<Tag> Tags { get; set; }
        public DbSet<Project> Projects { get; set; }

        public ThingsDataContext()
        {
           
        }

        public void SaveThing(Thing thing)
        {
            if (thing != null)
            {
                Things.Add(thing);
                SaveChanges();
            }
        }

        public IEnumerable<Thing> GetThings()
        {
            return Things.Select(p => p);
        }

        public IEnumerable<Thing> GetThings(Tag tag)
        {
            return Things.Where(p => p.Tags.Contains(tag));
        }
    }
}
